package com.hmdp.config;

import com.hmdp.common.LoginIntercepor;
import com.hmdp.common.RefreshTokenIntercepor;
import com.hmdp.entity.VoucherOrder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @author TJS
 * @Description
 * @create 2022/12/30 23:10
 */
@Configuration
public class MVCConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginIntercepor())
                .excludePathPatterns(
                        "/shop/**",
                        "/voucher/**",
                        "/shop-type/**",
                        "/upload/**",
                        "/blog/hot",
                        "/user/code",
                        "/user/login"
                ).order(1);
        registry.addInterceptor(new RefreshTokenIntercepor(stringRedisTemplate)).order(0);
    }

    @Bean
    public BlockingQueue<VoucherOrder> addBlockingQueue(){
        return new ArrayBlockingQueue<>(1024*1024);
    }
}
